package model.commands.environment;

import java.awt.Color;
import java.util.List;
import model.Environment;
import model.SyntaxErrorException;
import model.commands.Command;


/**
 * Name:
 * SETPALETTE color_index r g b
 * 
 * Description:
 * sets color corresponding at given color_index to given r g b color values
 * returns given color_index
 * note, color component values are nonnegative integers less than 256
 * specifying an amount of red, green, and blue
 * 
 * @author Erick Gonzalez
 */
public class SetPaletteCommand extends Command {
    private static final int RED = 1;
    private static final int BLUE = 2;
    private static final int GREEN = 3;

    @Override
    public int evaluate(Environment e) throws SyntaxErrorException {
        List<Command> arguments = getArguments();
        int colorIndex = arguments.get(0).evaluate(e);
        int red = arguments.get(RED).evaluate(e);
        int blue = arguments.get(BLUE).evaluate(e);
        int green = arguments.get(GREEN).evaluate(e);
        e.setColorIndex(colorIndex, new Color(red, blue, green));
        return colorIndex;
    }

}
